import { PageTool } from "../../../common/global/PageTool";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { PetIslandUtil } from "./PetIslandUtil";
import { SRobIslandPlayer } from "../../../../Message/Game/SRobIslandPlayer";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { EGuildPos } from "../../../../Message/Game/EGuildPos";
import { Cache } from "../../cache/Cache";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { PetIslandMemberInfoItemRenderer } from "./renderer/PetIslandMemberInfoItemRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GTileList } from "../../../../com/mui/controls/GTileList";
type int = number;
//class PetIslandMemberPanel
    
    export  class PetIslandMemberPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._pageTool = new PageTool([], 12);
            this.init();
            return;
        }

        /* internal  */onPageChange(arg1: Object /* flash.events.Event */=null): void
        {
            var loc1=this._pageSelecter.currentPage;
            this._list.dataProvider = new DataProvider(this._pageTool.getByPageNo(loc1));
            this._list.drawNow();
            return;
        }

        /* internal  */onDescBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._data.sortOn(["moveCD"], Array.NUMERIC);
            this.onPageChange();
            return;
        }

        /* internal  */onPosDescBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._data.sort(PetIslandUtil.sortMember);
            this.onPageChange();
            return;
        }

        /* internal  */onMoveDescBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._data.sortOn(["assistTimes"], Array.NUMERIC | Array.DESCENDING);
            this.onPageChange();
            return;
        }

        /* internal  */onAppointHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=this._list.selectedItem as SRobIslandPlayer;
            if (loc1) 
            {
                loc2 = this.guildPosNum;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandPosChangePanelShow, {"vo": loc1, "dic": loc2}));
            }
            return;
        }

        /* internal  */get guildPosNum(): Map<any, any> /* flash.utils.Dictionary */
        {
            var loc1=0;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            var loc5=0;
            var loc7=null;
            var loc6=new Map<any, any> /* flash.utils.Dictionary */();
            var loc8=0;
            var loc9=this._data;
            for(loc7 of loc9) 
            {
                if (loc7.guildPos == EGuildPos._EGuildPosOwner) 
                {
                    ++loc1;
                    continue;
                }
                if (loc7.guildPos == EGuildPos._EGuildPosCaptain) 
                {
                    ++loc2;
                    continue;
                }
                if (loc7.guildPos == EGuildPos._EGuildPosLeader) 
                {
                    ++loc3;
                    continue;
                }
                if (loc7.guildPos == EGuildPos._EGuildPosElite) 
                {
                    ++loc4;
                    continue;
                }
                if (loc7.guildPos != EGuildPos._EGuildPosMember) 
                {
                    continue;
                }
                ++loc5;
            }
            loc6[EGuildPos._EGuildPosOwner] = loc1;
            loc6[EGuildPos._EGuildPosCaptain] = loc2;
            loc6[EGuildPos._EGuildPosLeader] = loc3;
            loc6[EGuildPos._EGuildPosElite] = loc4;
            loc6[EGuildPos._EGuildPosMember] = loc5;
            return loc6;
        }

        /* internal  */setAppointBtnVisible(): void
        {
            var loc2=false;
            var loc3=null;
            var loc1=Cache.instance.role.entityInfo.entityId.id;
            var loc4=0;
            var loc5=this._data;
            for(loc3 of loc5) 
            {
                if (loc1 == loc3.entityId.id) 
                {
                    loc2 = loc3.guildPos >= EGuildPos._EGuildPosLeader;
                    break;
                }
                loc2 = false;
            }
            if (loc2) 
            {
                this.addChild(this._appointBtn);
            }
            else 
            {
                DisplayUtil.removeMe(this._appointBtn);
            }
            return;
        }

        /* internal  */set numTxt(arg1: int)
        {
            this._numTxt.text = Language.getStringByParam(28144, arg1);
            return;
        }

        public set data(arg1: Array<any>)
        {
            this._data = arg1;
            this._data.sortOn("guildPos", Array.NUMERIC | Array.DESCENDING);
            this._pageTool.array = this._data;
            this._pageSelecter.maxPage = this._pageTool.pagesCount;
            this.onPageChange();
            this.setAppointBtnVisible();
            this.numTxt = this._data.length;
            return;
        }

        /* internal  */init(): void
        {
            var loc1=GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat2, flash.text.TextFormatAlign.CENTER);
            ObjCreate.createGTextField(Language.getString(28134), 0, 30, 105, 20, this, loc1);
            ObjCreate.createGTextField(Language.getString(28241), 105, 30, 135, 20, this, loc1);
            ObjCreate.createGTextField(Language.getString(28135), 240, 30, 80, 20, this, loc1);
            ObjCreate.createGTextField(Language.getString(28136), 310, 30, 120, 20, this, loc1);
            ObjCreate.createGTextField(Language.getString(28248), 430, 30, 55, 20, this, loc1);
            ObjCreate.createGTextField(Language.getString(28137), 493, 30, 52, 20, this, loc1);
            var loc2=ObjCreate.createGButton("", 544, 32, 11, 17, this, "DescRedButton");
            loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onDescBtnClickHandler);
            var loc3=ObjCreate.createGButton("", 482, 32, 11, 17, this, "DescRedButton");
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onMoveDescBtnClickHandler);
            var loc4;
            (loc4 = ObjCreate.createGButton("", 405, 32, 11, 17, this, "DescRedButton")).addEventListener(flash.events.MouseEvent.CLICK, this.onPosDescBtnClickHandler);
            ObjCreate.createBg(3, 52, 550, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(3, 455, 550, 2, this, ImagesConst.SplitLine);
            this._list = ObjCreate.createTileList(0, 54, 560, 405, this);
            this._list.scrollPolicy = ScrollPolicy.OFF;
            this._list.columnWidth = 560;
            this._list.rowHeight = 33;
            this._list.selectable = true;
            this._list.setStyle("cellRenderer", PetIslandMemberInfoItemRenderer);
            this._pageSelecter = ObjCreate.createPageSelecter(200, 467, this);
            this._pageSelecter.mode = PageSelecter.CompleteMode;
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onPageChange);
            this._numTxt = ObjCreate.createGTextField("", 20, 468, 100, 20, this, GlobalStyle._textFormat2);
            this._appointBtn = ObjCreate.createGButton(Language.getString(28145), 490, 462, 49, 24);
            this._appointBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAppointHandler);
            return;
        }

        /* internal */ /* var */_numTxt: GTextFiled;

        /* internal */ /* var */_appointBtn: GButton;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_data: Array<any>;
    }
